﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Butcher.winform.EnterpriseForms.DivisionStorage
{
    public partial class DivisionStorageUpdate : Form
    {
        public DivisionStorageUpdate()
        {
            InitializeComponent();
            NEWthisHtml();
        }


        public void NEWthisHtml()
        {


            var id = DivisionStorageAdd.ids;

            string url = @"http://localhost:5229/api/Ending/SplitRUBack";
            HttpClient client = new HttpClient();
            SplitWarehousing approach = new SplitWarehousing();
            approach.SplitWarehousingid = id;
            var content = new StringContent(JsonSerializer.Serialize<SplitWarehousing>(approach));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var results = info["date"].Value<JToken>();
            textBox1.Text = results["documentNo"].ToString();
            textBox2.Text = results["grossWeight"].ToString();
            textBox3.Text = results["tare"].ToString();
            textBox4.Text = results["netWeight"].ToString();
            textBox5.Text = results["weightNum"].ToString();
            textBox6.Text = results["documentsDate"].ToString();









        }


        public class SplitWarehousing
        {

            public int SplitWarehousingid { get; set; }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            var id = DivisionStorageAdd.ids;

            string url = @"http://localhost:5229/api/Ending/SplitRUupdate";
            HttpClient client = new HttpClient();
            NEWDiv approach = new NEWDiv();


            approach.SplitWarehousingId = id;
            approach.GrossWeight = Convert.ToDecimal(textBox2.Text);
            approach.Tare = Convert.ToDecimal(textBox3.Text);
            approach.NetWeight = Convert.ToDecimal(textBox4.Text);
            approach.WeightNum = Convert.ToInt32(textBox5.Text);
            approach.DocumentsDate = Convert.ToDateTime(textBox6.Text);
            approach.DocumentNo = textBox1.Text;

            var content = new StringContent(JsonSerializer.Serialize<NEWDiv>(approach));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            if (info!=null)
            {
                MessageBox.Show("修改成功");
               Close();
            }


        }


        public class NEWDiv
        {

            /// <summary>
            /// 分割入库ID
            /// </summary>
            public int SplitWarehousingId { get; set; }
            /// <summary>
            /// 单据日期
            /// </summary>
            public DateTime DocumentsDate { get; set; }
            /// <summary>
            /// 单据号
            /// </summary>
            public string DocumentNo { get; set; }
        
    
     
            /// <summary>
            /// 称重件数
            /// </summary>
            public int WeightNum { get; set; }
            /// <summary>
            /// 毛重
            /// </summary>
            public decimal GrossWeight { get; set; }
            /// <summary>
            /// 皮重
            /// </summary>
            public decimal Tare { get; set; }
            /// <summary>
            /// 净重
            /// </summary>
            public decimal NetWeight { get; set; }
        



        }
    }
}
